import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import*
testCase="DBshop010_销售管理退货管理处理退货"

firefox=openBrowser(url)
DBshopLogin(firefox,userName,password)
firefox.find_element_by_link_text("用户中心").click()
firefox.find_element_by_link_text("退货申请").click()
firefox.find_element_by_link_text("点此申请退货").click()

rootPath=get_pro_rootpath() #获取项目的绝对路径
filePath=rootPath+r'\public\order1.txt' #拼接文件路径
orderNo=readFile(filePath) #读取文件中的订单编号

firefox.find_element_by_id("order_sn").send_keys(orderNo)
firefox.find_element_by_id("search-order").click()
time.sleep(3)
firefox.find_element_by_id("refund_info").send_keys("不想要了")
firefox.find_element_by_xpath('//button[@class="btn btn-primary"]').click()
time.sleep(2)
firefox.switch_to.alert.accept()
time.sleep(2)


# 登录后台管理系统,地址是"http://localhost/dbshop/admin",
firefox=openBrowser(urlAdmin)
#调用自定义函数进行后台的登录
DBshopLoginAdmin(firefox)
# 1.点击销售管理退货管理。
DBshopEnterMenu2(firefox,'销售管理','退货管理')
# 2.点击退货方式，选择框选择“退货到账户余额”点击“搜索”按钮。
firefox.find_element_by_xpath("//*[@value=1]").click()
firefox.find_element_by_xpath("//*[@class='btn btn-small btn-primary']").click()
#处理退货
firefox.find_element_by_link_text('处理退货').click()
a=firefox.find_element_by_xpath('//body').text
print(a)
b='订单总额\:\￥'
c='\nCopyright'
num=int(reGetString(a,b,c))
#输出退款金额
firefox.find_element_by_xpath("//*[@name='refund_price']").clear()
firefox.find_element_by_xpath("//*[@name='refund_price']").send_keys(num)
#提交处理结果
firefox.find_element_by_id("re_refund_info").send_keys("同意")
firefox.find_element_by_xpath("//button").click()
time.sleep(2)
#回到前台界面，点击“用户中心”，退货申请界面，查看退款成功
firefox=openBrowser(url)
DBshopLogin(firefox,userName,password)
firefox.find_element_by_link_text('用户中心').click()
firefox.find_element_by_link_text('退货申请').click()
firefox.find_element_by_xpath("//input[@name='search_content']").send_keys(orderNo)
firefox.find_element_by_xpath("//button[@class='btn btn-small btn-primary']").click()
#断言
try:
    firefox.find_element_by_xpath("//*[text()='退款成功']").text
    writeLog("%s 测试通过" % testCase)
except:
    writeLog("%s 测试不通过" % testCase)
    getPhoto(firefox)
firefox.quit()
